﻿using System;
using System.Drawing;
using System.Linq.Expressions;
using CloudShot.Editor.CanvasFigures;

namespace CloudShot.Utils.Tweens
{
  class ColorAnimationAdapter<T> : AnimationAdapter where T : IBoundingBoxFigure
  {
    private Color _colorBegin;
    private Color _colorEnd;

    public override void SetValue(float value)
    {
      int a = (int)(_colorBegin.A + ((_colorEnd.A - _colorBegin.A) * value));
      int r = (int)(_colorBegin.R + ((_colorEnd.R - _colorBegin.R) * value));
      int g = (int)(_colorBegin.G + ((_colorEnd.G - _colorBegin.G) * value));
      int b = (int)(_colorBegin.B + ((_colorEnd.B - _colorBegin.B) * value));

      PropertyInfo.SetValue(Target, Color.FromArgb(a, r, g, b), null);
    }

    public ColorAnimationAdapter(T target, Expression<Func<T, Color>> expression, Color to)
      : base(target, expression.GetPropertyInfo(), 0, 1)
    {
      _colorBegin = (Color)PropertyInfo.GetValue(target);
      _colorEnd = to;
    }

    public override string ToString()
    {
      return string.Format("Name = {0}, start = {1}, end = {2}", Name, _colorBegin, _colorEnd);
    }
  }
}
